<?php

class AdminController extends Zend_Controller_Action
{

    /**
     * FlashMessenger
     *
     * @var Zend_Controller_Action_Helper_FlashMessenger
     */
    protected $_flashMessenger = null;

    /**
     * Текущая локаль.
     * @var string
     */
    protected $_locale;

    public function init()
    {
        die;
        $this->_helper->layout()->setLayout('admin-layout');
//        $this->_helper->layout()->disableLayout();
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
    }

    public function localesAction()
    {
        $localesManager = new \Managers\Locales();
        $qb = $localesManager->qb();
        $grid = $this->grid($qb);

        $this->view->form = $grid->deploy();

        $this->renderScript('/grid/form.phtml');
    }

    public function pagesAction()
    {

        $pagesManager = new \Managers\Pages();
        $qb = $pagesManager->qb();
        $grid = $this->grid($qb);

        $this->view->form = $grid->deploy();

        $this->renderScript('/grid/form.phtml');
    }

    public function grid($qb, $id = '')
    {
        $view = new Zend_View();
        $view->setEncoding('UTF-8');

        $config = new Zend_Config_Ini(APPLICATION_PATH . '/grids/grid.ini', 'production');

        $grid = Bvb_Grid::factory('Table', $config, $id);

        $grid->setEscapeOutput(true);
        $grid->setExport(array('csv', 'excel', 'pdf'));
        $grid->setView($view);

        $gridManager = new \Managers\Grid();
        $em = $gridManager->em();
        $source = new Bvb_Grid_Source_Doctrine2($qb, $em);
        $grid->setSource($source);
        $grid->updateColumn('id', array('hidden' => true));
        $grid->updateColumn('content', array('hidden' => true));

        $form = new Bvb_Grid_Form();
        $form->setAdd(true)->setEdit(true)->setDelete(true)->setAddButton(true);
        $grid->setForm($form);

        return $grid;
    }


}
